package com.itita.ww2.handler.requesthandler.worldmap;

import java.sql.SQLException;

import com.itita.ww2.core.MessageHandler;
import com.itita.ww2.core.WW2Exception;
import com.itita.ww2.game.alliance.AllianceService;
import com.itita.ww2.game.worldmap.WorldMapService;
import com.itita.ww2.model.enums.AlWMDataFields;
import com.itita.ww2.utils.handler.IRequestOper;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.entities.data.SFSArray;
import com.smartfoxserver.v2.entities.data.SFSObject;

/**
 * 天下大势
 * World Trend
 * @author NorthLan
 *
 */
public class GetTrend implements IRequestOper {

	@Override
	public boolean execute(String requestCMD, User user, ISFSObject params) throws WW2Exception, SQLException {
		ISFSObject backObj = new SFSObject();
		// 最新激战 10条
		backObj.putSFSArray("lastestLog", WorldMapService.getLastestBattle());
		// 最强联盟 前5 (占城数)
		ISFSArray arr = AllianceService.getAllAllianceRanking(AlWMDataFields.CITY_COUNT, 1, 5);
		ISFSArray arr2 = new SFSArray();
		for (int i = 0; i < arr.size(); ++i) {
			if (arr.getSFSObject(i).getInt("count") != 0) {
				arr2.addSFSObject(arr.getSFSObject(i));
			}
		}
		backObj.putSFSArray("strongest", arr2);
		MessageHandler.getInstance().sendMsg(requestCMD, backObj, user, null, true);
		return true;
	}

}
